﻿using MediatR;
using ProductionManagement.Application.Command.ProOrderCommand;
using ProductionManagement.Infrstructre.lnterface;

namespace ProductionManagement.Application.CommandHandler.ProOrderCommandHandlers
{
    public class DelProOrderCommandHandlers:IRequestHandler<DelProOrderCommand,int>
    {
        private readonly IProOrderRepository _proOrderRepository;

        public DelProOrderCommandHandlers(IProOrderRepository proOrderRepository)
        {
            _proOrderRepository = proOrderRepository;
        }

        public async Task<int> Handle(DelProOrderCommand request, CancellationToken cancellationToken)
        {
            var list = (await _proOrderRepository.GetAll()).Where(x => request.Ids.Contains(x.POId)).ToList();

            foreach (var item in list)
            {
                item.IsDel = true;
                await _proOrderRepository.UpdAsync(item);
            }

            return 1;
        }
    }
}
